<template>
  <div>
    <el-scrollbar wrap-class="scrollbar-wrapper">
      <el-menu
        :default-active="activePath"
        :default-openeds="openeds"
        :collapse-transition="true"
        :unique-opened="true"
        @open="handleOpen"
        @close="handleClose"
      >
        <el-submenu index="1">
          <template slot="title">
            <i class="el-icon-location"></i>
            <span>导航一</span>
          </template>

          <component :is="componentId" :to="{ path: '/'}">
            <el-menu-item index="/">home</el-menu-item>
          </component>
          <component :is="componentId" :to="{ path: '/about'}">
            <el-menu-item index="/about">about</el-menu-item>
          </component>

          <el-menu-item index="1-3">other</el-menu-item>
        </el-submenu>
        <el-submenu index="2">
          <template slot="title">
            <i class="el-icon-star-on"></i>
            <span>导航二</span>
          </template>

          <component :is="componentId" :to="{ path: '/menu_one'}">
            <el-menu-item index="/menu_one">menu_one</el-menu-item>
          </component>
          <component :is="componentId" :to="{ path: '/menu_two'}">
            <el-menu-item index="/menu_two">menu_two</el-menu-item>
          </component>

          <el-menu-item index="2-3">other</el-menu-item>
        </el-submenu>
      </el-menu>
    </el-scrollbar>
  </div>
</template>
<script>
export default {
  data() {
    return {
      openeds: ["1"],
      componentId: "router-link"
    };
  },
  computed: {
    activePath() {
      const { meta, path } = this.$route;
      console.log("path:" + path);
      return path;
      //return meta && meta.activePath ? meta.activePath : path;
    }
  },
  methods: {
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
      open(key);
    }
  }
};
</script>

<style lang="scss" >
</style>
